from typing import Dict, Any
from fastapi import Depends

class StateManager:
    _instance = None
    
    def __new__(cls):
        if cls._instance is None:
            cls._instance = super().__new__(cls)
            # 初始化共享状态
            cls._instance.state = {} # : Dict[str, Any]
        return cls._instance
    
    def set(self, key: str, value: Any):
        """设置状态"""
        self.state[key] = value
        
    def get(self, key: str, default: Any = None) -> Any:
        """获取状态"""
        return self.state.get(key, default)
    
    def delete(self, key: str):
        """删除状态"""
        if key in self.state:
            del self.state[key]
            
    def clear(self):
        """清空所有状态"""
        self.state.clear()

# 创建全局实例
state_manager = StateManager()

# 依赖注入函数
def get_state_manager() -> StateManager:
    return state_manager 